/*******************************************************************************
 * Copyright (C) 2011 Angelo Zerr <angelo.zerr@gmail.com>, Pascal Leclercq <pascal.leclercq@gmail.com>
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Angelo ZERR - initial API and implementation
 *     Pascal Leclercq - initial API and implementation
 *******************************************************************************/
package kr.nexmore.slmsample2.nebula_sample;

import javax.annotation.PostConstruct;

import kr.nexmore.slmsample2.vo.TagVo;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.nebula.widgets.pagination.collections.PageResultContentProvider;
import org.eclipse.nebula.widgets.pagination.renderers.navigation.ResultAndNavigationPageLinksRendererFactory;
import org.eclipse.nebula.widgets.pagination.table.PageableTable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

/**
 * Demonstrates the Nebula Pagination Control
 * 
 * @author Angelo ZERR
 */
public class BoardPart3 extends AbstractExampleTab {

	private static final String BUNDLE = "org.eclipse.nebula.widgets.pagination.example";

	/**
	 * @wbp.parser.entryPoint
	 */
	@Override
	@PostConstruct
	public Control createControl(Composite parent) {


		// 1) Create pageable table with 10 items per page
		// This SWT Component create internally a SWT Table+JFace TreeViewer
		int pageSize = 10;
		parent.setLayout(null);
		PageableTable pageableTable = new PageableTable(parent, SWT.BORDER, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, pageSize,
				PageResultContentProvider.getInstance(), null, ResultAndNavigationPageLinksRendererFactory.getFactory());
		GridData gridData = (GridData) pageableTable.getCompositeBottom().getLayoutData();
		gridData.horizontalAlignment = SWT.CENTER;
		gridData.verticalAlignment = SWT.CENTER;

		pageableTable.setBounds(0, 0, 942, 645);

		// 2) Initialize the table viewer + SWT Table
		TableViewer viewer = pageableTable.getViewer();
		viewer.setContentProvider(ArrayContentProvider.getInstance());
		viewer.setLabelProvider(new LabelProvider());

		Table table = viewer.getTable();
		GridData gd_table = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_table.widthHint = 903;
		table.setLayoutData(gd_table);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);

		pageableTable.setPageLoader(BoardWidgetServices.getInstance());
		pageableTable.setCurrentPage(0);

		TableViewerColumn tableViewerColumn = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_rownum = tableViewerColumn.getColumn();
		col_rownum.setWidth(100);
		col_rownum.setText("번호");
		tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				
				return String.valueOf(p.getRownum());
			}
		});

		TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_tag_id = tableViewerColumn_1.getColumn();
		col_tag_id.setWidth(100);
		col_tag_id.setText("일련번호");
		tableViewerColumn_1.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getTag_id();
			}
		});

		TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_organization_name = tableViewerColumn_2.getColumn();
		col_organization_name.setWidth(100);
		col_organization_name.setText("담당기관");
		tableViewerColumn_2.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getOrganization_name();
			}
		});

		TableViewerColumn tableViewerColumn_3 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_tag_status = tableViewerColumn_3.getColumn();
		col_tag_status.setWidth(100);
		col_tag_status.setText("사용여부");
		tableViewerColumn_3.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getTag_status();
			}
		});

		TableViewerColumn tableViewerColumn_4 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_tag_dist_status = tableViewerColumn_4.getColumn();
		col_tag_dist_status.setWidth(100);
		col_tag_dist_status.setText("단말기 상태");
		tableViewerColumn_4.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getTag_dist_status();
			}
		});

		TableViewerColumn tableViewerColumn_5 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_name = tableViewerColumn_5.getColumn();
		col_name.setWidth(100);
		col_name.setText("성명");
		tableViewerColumn_5.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getName();
			}
		});

		TableViewerColumn tableViewerColumn_6 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_handi_per_group_name = tableViewerColumn_6.getColumn();
		col_handi_per_group_name.setWidth(100);
		col_handi_per_group_name.setText("대상자 구분");
		tableViewerColumn_6.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getHandi_per_group_name();
			}
		});

		TableViewerColumn tableViewerColumn_7 = new TableViewerColumn(pageableTable.getViewer(), SWT.NONE);
		TableColumn col_address = tableViewerColumn_7.getColumn();
		col_address.setWidth(100);
		col_address.setText("주소");
		tableViewerColumn_7.setLabelProvider(new ColumnLabelProvider() {

			@Override
			public String getText(Object element) {
				TagVo p = (TagVo) element;
				return p.getAddress_basic();
			}
		});
		
		
		pageableTable.refreshPage();

		return parent;
	}
	
	private void createsample(TableViewer viwer){
		TableViewerColumn tableViewerColumn_7 = new TableViewerColumn(viwer, SWT.NONE);
		TableColumn col_address = tableViewerColumn_7.getColumn();
		col_address.setWidth(100);
		col_address.setText("주소");
		
		
	}

	@Override
	public void createParameters(Composite parent) {
		parent.setLayout(new GridLayout(2, true));
	}

	@Override
	public String[] createLinks() {
		String[] links = { "<a href=\"http://angelozerr.wordpress.com/2012/01/06/nebula_pagination/\" >Pagination Control Article</a>" };
		return links;
	}

}
